#ifndef _EPOLLPOLLER_
#define _EPOLLPOLLER_

#include "Poller.h"
#include "Timestamp.h"

#include <vector>
#include <sys/epoll.h>

class Channel;
/*
    epoll使用：
        epoll_create
        epoll_ctl add/mod/del
        epoll_wait
*/
class EPollPoller : public Poller{
public:
    EPollPoller(EventLoop *loop);
    ~EPollPoller() override;
    Timestamp poll(int timeoutMs, ChannelList *activeChannels) override;
    //這裏是給channel調用的，因爲channel不能直接調用Poller，而是需要通過EventLoop去調用Poller
    void updateChannel(Channel *channel) override;
    void removeChannel(Channel *channel) override;
private:
    static const int kInitEventListSize = 16;
    //填寫活躍的連接
    void fillActiveChannel(int numEvents, ChannelList *activeChannels) const;
    //更新channel的通道
    void update(int operation, Channel *channel);
    using EventList = std::vector<epoll_event>;

    int epollfd_;
    EventList events_;  //存儲發生事件的fd
};

#endif